package com.qys.livesMall.app.user.controller.sys;

import com.qys.livesMall.app.user.model.dto.sys.UserLevelDTO;
import com.qys.livesMall.app.user.model.dto.sys.UserLevelUpgradationDTO;
import com.qys.livesMall.app.user.model.entity.AppUserLevel;
import com.qys.livesMall.app.user.service.AppUserLevelService;
import com.qys.livesMall.common.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2023-06-06
 */
@RestController
@Tag(name = "sys-app用户等级")
@RequestMapping("/sys/app/user/level")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysAppUserLevelController {

    private final AppUserLevelService userLevelService;

    @Operation(summary = "用户等级列表")
    @GetMapping(value = "/all")
    public R<List<AppUserLevel>> all() {
        return R.ok(userLevelService.list());
    }

    @Operation(summary = "新增用户等级")
    @PostMapping(value = "/save")
    public R<Void> save(@RequestBody @Validated UserLevelDTO userLevelDTO) {
        userLevelService.save(userLevelDTO);
        return R.ok();
    }

    @Operation(summary = "修改用户等级")
    @PutMapping(value = "/edit")
    public R<Void> edit(@RequestBody @Validated UserLevelDTO userLevelDTO) {
        userLevelService.editById(userLevelDTO);
        return R.ok();
    }

    @Operation(summary = "删除用户等级信息")
    @DeleteMapping(value = "/{id}")
    public R<Void> delete(@PathVariable Integer id) {
        userLevelService.deleteById(id);
        return R.ok();
    }


    @Operation(summary = "新增用户升级条件")
    @PostMapping(value = "/saveUpgradation")
    public R<Void> save(@RequestBody @Validated UserLevelUpgradationDTO upgradationDTO) {
        userLevelService.saveUpgradation(upgradationDTO);
        return R.ok();
    }

    @Operation(summary = "修改用户升级条件")
    @PutMapping(value = "/editUpgradationById")
    public R<Void> edit(@RequestBody @Validated UserLevelUpgradationDTO upgradationDTO) {
        userLevelService.editUpgradationById(upgradationDTO);
        return R.ok();
    }

    @Operation(summary = "更新用户等级信息")
    @PostMapping(value = "updateLevel/{id}")
    public R<Void> updateLevel(@PathVariable Long id) {
        userLevelService.adjustUserLevel(id);
        return R.ok();
    }
}
